package com.adtec.thread;

import java.util.concurrent.*;

/**
 * 5种创建线程方式
 */
public class ThreadCreats {

    static class Thread01 extends  Thread{
        @Override
        public void run() {
            System.out.println("hallll");
        }
    }

    static class Thread02 implements Runnable {
        @Override
        public void run() {
                System.out.println("hal222");
        }
    }

    static class MyCallable implements Callable<String> {

        @Override
        public String call() throws Exception {
            return "hello";
        }
    }

    public static void main(String[] args) {

        new Thread01().start();

        new Thread(new Thread02()).start();

        new Thread(()->{
            System.out.println("33333333333");
        }).start();

        ExecutorService server  = Executors.newCachedThreadPool();

        server.execute(new Thread02());

        Future future = server.submit(new MyCallable());

        try {
            System.out.println( future.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        server.shutdown();    
    }
}
